package okl.test.motionChart.parts
{
	import com.fizzback.utils.ColorsHelper;
	
	import flash.geom.Matrix;
	
	import mx.core.UIComponent;
	import mx.graphics.GradientBase;
	
	/**
	 *	@author "oleksandr.kulinchenko@gmail.com"
	 */
	public class ColorScaleIndicator extends UIComponent
	{
		public function ColorScaleIndicator()
		{
			super();
		}
		
		private var _gradient:GradientBase;
		private var _maximum:Number=10;
		private var _minimum:Number=0;

		public function get minimum():Number
		{
			return _minimum;
		}

		public function set minimum(value:Number):void
		{
			_minimum = value;
			invalidateDisplayList();
		}

		public function get maximum():Number
		{
			return _maximum;
		}

		public function set maximum(value:Number):void
		{
			_maximum = value;
			invalidateDisplayList();
		}
		
		/**
		 * Background color gradients 
		 */
		public function get gradient():GradientBase
		{
			return _gradient;
		}
		
		public function set gradient(value:GradientBase):void
		{
			_gradient = value;
			invalidateDisplayList();
		}
		
		//TODO: Horizontal direction
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			this.graphics.clear();
			if(gradient==null)return;
			var matrix:Matrix= new Matrix();
			matrix.createGradientBox(unscaledWidth/2, unscaledHeight, (Math.PI/180)*90, 0, 0);
			ColorsHelper.beginGradientFill(this.graphics, gradient, matrix);			
			this.graphics.drawRect(0, 0, unscaledWidth/2, unscaledHeight);
			this.graphics.endFill();
			
			var ticksCount:Number = 10;
			var step:Number = unscaledHeight/ticksCount;
			var tickX:Number = unscaledWidth/2;
			var tickW:Number = 5;
			var curY:Number=0;
			graphics.lineStyle(1, 0x000000);
			for(var i:uint; i<ticksCount; i++){
				graphics.moveTo(tickX, curY);
				graphics.lineTo(tickX+tickW, curY);
				curY+=step;
			}			
			
		}
	}
}